$.ajaxSetup ({cache: false});
var ajax_load = "<img class='loading' src='modules/reequipment/xarimages/ajax-loader.gif' alt='loading...' style='padding-left: 50px; padding-top: 50px;' />";
var update_load = "<img class='loading' src='modules/reequipment/xarimages/ajax-loader.gif' alt='loading...'  /> Updating...";

/* index.php?module=reequipment&func=pm&equipment_id=1&model_id=1&area_id=1 */
function ShowPM(equipment_id, model_id, area_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=pm&pageName=module&equipment_id='+equipment_id+'&model_id='+model_id+'&area_id='+area_id;
    $.scrollTo( '700px', 800);
    $("#result").fadeIn();
    $("#result").html(ajax_load);
    $.get(
        loadUrl,
        {language: "php", version: 5},
        function(responseText){
            $("#result").html(responseText);
            /* Also load the javascript needed for the pm page. */
            $.ajax({
                type: "GET",
                url: "modules/reequipment/xartemplates/includes/ajax.pm.js",
                dataType: "script"
            });
        },
        "html"
    );
    window.location.hash = '#result';
 }

function ShowOpenMaintenance(equipment_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=maintenance&phase=show_maintenance&pageName=module&equipment_id='+equipment_id;
    $.scrollTo( '700px', 800);
    $("#result").fadeIn();
    $("#result").html(ajax_load);
    $.get(
        loadUrl,
        {language: "php", version: 5},
        function(responseText){
            $("#result").html(responseText);
             /* Also load the javascript needed for the pm page. */
            $.ajax({
                type: "GET",
                url: "modules/coxjquery/xartemplates/includes/jquery.textareaexpander.js",
                dataType: "script"
            });
            $.ajax({
                type: "GET",
                url: "modules/reequipment/xartemplates/includes/ajax.show_maintenance.js",
                dataType: "script"
            });
        },
        "html"
    );
    window.location.hash = '#result';
 }

 function ShowParts(equipment_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=items&phase=show_parts&pageName=module&equipment_id='+equipment_id;
    $.scrollTo( '700px', 800);
    $("#result").fadeIn();
    $("#result").html(ajax_load);
    $.get(
        loadUrl,
        {language: "php", version: 5},
        function(responseText){
            $("#result").html(responseText);
             /* Also load the javascript needed for the pm page. */
            $.ajax({
                type: "GET",
                url: "modules/coxjquery/xartemplates/includes/jquery.textareaexpander.js",
                dataType: "script"
            });
            $.ajax({
                type: "GET",
                url: "modules/reequipment/xartemplates/includes/ajax.show_parts.js",
                dataType: "script"
            });
        },
        "html"
    );
    window.location.hash = '#result';
 }

function UpdateEquipment(equipment_id){
    var loadUrl = 'index.php?module=reequipment&type=user&func=equipment&phase=update&pageName=module';
    var newValue = $('#machine_name').val();
    $("#click_to_update").hide();
    $("#update_result").fadeIn().html(update_load).delay("500").fadeOut('slow');
    $.post(
    loadUrl,
    $("#equipment_form").serialize()
    );
    $("#click_to_update").delay("850").fadeIn();
    $("#eq_name").text(newValue);
    $("#menu_"+equipment_id).text(newValue);
}

function ChangeModel(){
    $("#show_model").hide();
    $("#change_model").show();
}

function ShowModel(){
    var newValue = $('#model_id_select :selected').text();
    $("#model_id_text").val(newValue);
    $("#change_model").blur().hide();
    $("#show_model").blur().show();
}

function ChangeVoltage(){
    $("#show_voltage").hide();
    $("#change_voltage").show();
}

function ShowVoltage(){
    var newValue = $('#voltage_select :selected').text();
    $("#voltage_text").val(newValue);
    $("#change_voltage").blur().hide();
    $("#show_voltage").blur().show();
}

function BackTop(){
    $("#result").fadeOut();
    $.scrollTo( '0px', 800);
}
